home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 13820 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: blv-pm12-ip6.halcyon.com!user
  2. From: hawkfish@punchdeck.com (Richard Wesley)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: STL Implementation
  5. Date: Wed, 27 Mar 1996 08:48:14 -0800
  6. Organization: Electric Fish, Inc.
  7. Message-ID: <hawkfish-2703960848140001@blv-pm12-ip6.halcyon.com>
  8. References: <3158429C.242F@cgsd.com>
  9. NNTP-Posting-Host: blv-pm12-ip6.halcyon.com
  10. X-Newsreader: Yet Another NewsWatcher 2.1.2
  11.  
  12. In article <3158429C.242F@cgsd.com>, mckenna@cgsd.com wrote:
  13.  
  14. >In C++ I can make a class with a pointer 
  15. >to a member of that same class.
  16. >
  17. >   class foo
  18. >    {
  19. >             int a;
  20. >      foo * child;
  21. >    };
  22. >
  23. >With STL I would like my class to have a point to a list
  24. >of objects in this class.
  25. >
  26. >   class foo
  27. >    {
  28. >              int a;
  29. >       list<foo> * child_list;
  30. >    };
  31. >
  32. >But the pointer to the list<foo> can not be constructed
  33. >because foo isn't finished being defined yet.
  34. >
  35. >Is there a work around for this? Is there some other
  36. >implementation that I should be considering.
  37.  
  38. Try
  39.  
  40. list<foo*> child_list;
  41.  
  42. The list will then be automatically created and deleted with foo objects
  43. and you can manipulate the child list without doing deep copies all over
  44. the place.
  45.  
  46. Where the references get hairy is when you start using smart pointers
  47. instead of dumb ones (like foo *).  Then you might want to use the
  48. Composite pattern and have the child list in multi_foo derived class.
  49.  
  50.  
  51. - rmgw
  52.  
  53. http://www.halcyon.com/hawkfish/Index.html
  54.  
  55. ----------------------------------------------------------------------------
  56. Richard Wesley             | "I don't know about your dreams
  57. hawkfish@punchdeck.com     |  But mine are sort of hackneyed"
  58. hawkfish@electricfish.com  |   - Laurie Anderson, "Talk Normal"
  59. ----------------------------------------------------------------------------
  60.